<template>
  <el-form :model="Pass" :rules="rules" ref="PassForm">
    <el-form-item label="旧密码" prop="oldPassword">
      <el-input type="password" v-model="Pass.oldPassword" />
    </el-form-item>
    <el-form-item label="新密码" prop="newPassword">
      <el-input type="password" v-model="Pass.newPassword" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import {updatePass} from '@/api/user';
export default {
  data() {
    return {
      Pass: {
        oldPassword: '',
        newPassword: '',
      },
      rules: {
        oldPassword: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
        newPassword: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
      },
    }
  },
  methods: {
    submit() {
      this.$refs.PassForm.validate(async(valid) => {
        if (valid) {
          let res = null
          res = await updatePass(this.Pass)
          //判断是否成功
            if (res.success) {
                this.$message.success(res.message)
            } else {
                this.$message.error(res.message)
                }  
        }
      })
    }
  }
}
</script>
